<!-- -->
<template>
  <div id='update'>
    <div class="tradetop">升级</div>
    <!-- 我要挂卖 -->
    <div class="tradesell">
        <div class="message">
            <ul>
                <li>会员名：&emsp;&emsp;<input type="text" v-model="name" placeholder="请输入用户名"></li>
                <!-- <li>电子邮箱：&emsp;<input type="text" v-model="email" readonly="readonly"></li> -->
                <li>
                    <div>会员等级：&nbsp;&nbsp;  
                        <select class="openup" v-model="selected">
                            <option value="index"  v-for="(item,index) in rank" :value='item.rank_money' :key="index">{{item.rank_money}}</option>
                            <!-- <option value="2">{{item}}</option> -->
                        </select>
                    </div>
                </li>
                <li>安全密码：&emsp;<input type="password" v-model="password" placeholder="请输入你的安全密码"></li>
            </ul>
        </div>
        <div class="btn">
            <button @click="update">确定升级</button>
            <!-- <button>取消</button> -->
        </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "update",
  data() {
    return {
      name: "",
      email: "",
      password: "",
      rank: [],
      selected: "100"
    };
  },
  created () {
    this.loadmes();
  },
  methods: {
    loadmes() {
      this.axios
        .post("User/user_shengji_jihuo")
        .then(({ data }) => {
          console.log(data);
          // this.name = data.user.user_name;
          // this.email = data.user.user_email;
          this.rank = data.rank;
        })
        .catch(function(error) {
          console.log(error);
        });
    },
    update() {
      console.log(this.selected);
      this.axios
        .post("User/user_shengji_jihuo_cl", {
          password: this.password,
          rank: this.selected,
          name: this.name
        })
        .then(({ data }) => {
          console.log(data);
          if (data.status === "1") {
            this.$message({ message: "密码错误", type: "error" });
          } else if (data.status === "2") {
            this.$message({ message: "激活码不足", type: "error" });
          } else if (data.status === "3") {
            this.$message({ message: "注册币不足", type: "error" });
          } else if (data.status === "4") {
            this.$router.push("home");
            this.$message({ message: "成功", type: "success" });
          } else if (data.status === "5") {
            this.$message({ message: "没有该用户", type: "error" });
          } else if (data.status === "6") {
            this.$message({ message: "此帐号未激活，不能升级", type: "error" });
          }
        })
        .catch(function(error) {
          console.log(error);
        });
    }
  }
};
</script>
<style lang='scss' scoped>
#update {
  .tradetop {
    width: 100%;
    height: 55px;
    line-height: 65px;
    font-size: 13px;
    font-family: MicrosoftYaHei-Bold;
    color: rgba(0, 0, 0, 1);
    font-weight: 700;
    padding-left: 25px;
    box-sizing: border-box;
    border-bottom: 1px solid rgba(153, 153, 153, 1);
  }
  .tradesell {
    .message {
      margin-left: 40px;
      margin-top: 10px;
      li {
        line-height: 50px;
        font-size: 12px;
        font-family: MicrosoftYaHei;
        color: rgba(102, 102, 102, 1);
      }
      input {
        width: 209px;
        height: 33px;
        padding-left: 5px;
        border-radius: 2px;
        border: 1px solid rgba(151, 151, 151, 1);
      }
      .openup {
        width: 216px;
        height: 35px;
        padding-left: 5px;
        border-radius: 2px;
        border: 1px solid rgba(151, 151, 151, 1);
      }
    }
    .btn {
      margin-top: 50px;
      margin-left: 40px;
      button {
        cursor: pointer;
        width: 82px;
        height: 33px;
        background: rgba(224, 3, 0, 1);
        font-size: 12px;
        font-family: MicrosoftYaHei;
        color: rgba(255, 255, 255, 1);
        border-radius: 2px;
      }
      button:nth-of-type(2) {
        margin-left: 25px;
        background: rgba(225, 225, 225, 1);
        color: rgba(0, 0, 0, 1);
      }
    }
  }
}
</style>